from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-02 14:11:19.857972
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 02, Apr, 2021
Time: 14:11:24
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.2975
Nobs: 249.000 HQIC: -48.0571
Log likelihood: 2956.98 FPE: 8.07217e-22
AIC: -48.5688 Det(Omega_mle): 5.66352e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.445551 0.127219 3.502 0.000
L1.Burgenland 0.071420 0.062996 1.134 0.257
L1.Kärnten -0.217249 0.054366 -3.996 0.000
L1.Niederösterreich 0.087881 0.139764 0.629 0.529
L1.Oberösterreich 0.216259 0.130096 1.662 0.096
L1.Salzburg 0.267419 0.070567 3.790 0.000
L1.Steiermark 0.138880 0.091075 1.525 0.127
L1.Tirol 0.113569 0.061894 1.835 0.067
L1.Vorarlberg -0.030216 0.057188 -0.528 0.597
L1.Wien -0.080444 0.117348 -0.686 0.493
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.484990 0.151867 3.194 0.001
L1.Burgenland 0.004847 0.075201 0.064 0.949
L1.Kärnten 0.336577 0.064899 5.186 0.000
L1.Niederösterreich 0.103285 0.166842 0.619 0.536
L1.Oberösterreich -0.076407 0.155300 -0.492 0.623
L1.Salzburg 0.212105 0.084239 2.518 0.012
L1.Steiermark 0.116527 0.108720 1.072 0.284
L1.Tirol 0.137475 0.073885 1.861 0.063
L1.Vorarlberg 0.156842 0.068268 2.297 0.022
L1.Wien -0.463302 0.140083 -3.307 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298628 0.062079 4.810 0.000
L1.Burgenland 0.097701 0.030740 3.178 0.001
L1.Kärnten -0.014953 0.026529 -0.564 0.573
L1.Niederösterreich 0.047547 0.068201 0.697 0.486
L1.Oberösterreich 0.286494 0.063483 4.513 0.000
L1.Salzburg 0.017195 0.034435 0.499 0.618
L1.Steiermark 0.021625 0.044442 0.487 0.627
L1.Tirol 0.066826 0.030202 2.213 0.027
L1.Vorarlberg 0.083273 0.027906 2.984 0.003
L1.Wien 0.101142 0.057262 1.766 0.077
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.214022 0.063476 3.372 0.001
L1.Burgenland 0.021015 0.031432 0.669 0.504
L1.Kärnten 0.008119 0.027126 0.299 0.765
L1.Niederösterreich 0.050682 0.069735 0.727 0.467
L1.Oberösterreich 0.400810 0.064911 6.175 0.000
L1.Salzburg 0.082847 0.035209 2.353 0.019
L1.Steiermark 0.134358 0.045442 2.957 0.003
L1.Tirol 0.048640 0.030882 1.575 0.115
L1.Vorarlberg 0.082623 0.028534 2.896 0.004
L1.Wien -0.043080 0.058550 -0.736 0.462
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.512066 0.124192 4.123 0.000
L1.Burgenland 0.083533 0.061497 1.358 0.174
L1.Kärnten 0.010864 0.053072 0.205 0.838
L1.Niederösterreich -0.030158 0.136438 -0.221 0.825
L1.Oberösterreich 0.133998 0.127000 1.055 0.291
L1.Salzburg 0.056712 0.068888 0.823 0.410
L1.Steiermark 0.093002 0.088908 1.046 0.296
L1.Tirol 0.211331 0.060421 3.498 0.000
L1.Vorarlberg 0.029756 0.055828 0.533 0.594
L1.Wien -0.092342 0.114555 -0.806 0.420
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187979 0.096593 1.946 0.052
L1.Burgenland -0.014025 0.047831 -0.293 0.769
L1.Kärnten -0.015945 0.041278 -0.386 0.699
L1.Niederösterreich -0.027319 0.106118 -0.257 0.797
L1.Oberösterreich 0.417426 0.098777 4.226 0.000
L1.Salzburg 0.010747 0.053579 0.201 0.841
L1.Steiermark -0.004792 0.069150 -0.069 0.945
L1.Tirol 0.157794 0.046994 3.358 0.001
L1.Vorarlberg 0.057668 0.043421 1.328 0.184
L1.Wien 0.235551 0.089098 2.644 0.008
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.247344 0.119738 2.066 0.039
L1.Burgenland 0.018788 0.059292 0.317 0.751
L1.Kärnten -0.063580 0.051169 -1.243 0.214
L1.Niederösterreich -0.058144 0.131545 -0.442 0.658
L1.Oberösterreich 0.012136 0.122445 0.099 0.921
L1.Salzburg 0.077050 0.066417 1.160 0.246
L1.Steiermark 0.337916 0.085719 3.942 0.000
L1.Tirol 0.456458 0.058254 7.836 0.000
L1.Vorarlberg 0.149504 0.053825 2.778 0.005
L1.Wien -0.172280 0.110447 -1.560 0.119
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.141093 0.141284 0.999 0.318
L1.Burgenland 0.050267 0.069961 0.719 0.472
L1.Kärnten -0.070584 0.060376 -1.169 0.242
L1.Niederösterreich 0.192841 0.155216 1.242 0.214
L1.Oberösterreich -0.004438 0.144479 -0.031 0.975
L1.Salzburg 0.202635 0.078369 2.586 0.010
L1.Steiermark 0.115965 0.101144 1.147 0.252
L1.Tirol 0.056454 0.068737 0.821 0.411
L1.Vorarlberg 0.100730 0.063511 1.586 0.113
L1.Wien 0.219194 0.130321 1.682 0.093
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.589766 0.076771 7.682 0.000
L1.Burgenland -0.040156 0.038015 -1.056 0.291
L1.Kärnten -0.025603 0.032807 -0.780 0.435
L1.Niederösterreich 0.012488 0.084341 0.148 0.882
L1.Oberösterreich 0.329705 0.078507 4.200 0.000
L1.Salzburg 0.019173 0.042584 0.450 0.653
L1.Steiermark -0.031603 0.054960 -0.575 0.565
L1.Tirol 0.087623 0.037350 2.346 0.019
L1.Vorarlberg 0.110787 0.034511 3.210 0.001
L1.Wien -0.043891 0.070814 -0.620 0.535
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.138257 0.036746 0.162688 0.217550 0.059279 0.078068 -0.005213 0.153204
Kärnten 0.138257 1.000000 0.018452 0.204250 0.178928 -0.066198 0.159309 0.022400 0.307858
Niederösterreich 0.036746 0.018452 1.000000 0.245300 0.071569 0.301180 0.137985 0.029835 0.304245
Oberösterreich 0.162688 0.204250 0.245300 1.000000 0.299646 0.276066 0.089327 0.059720 0.136485
Salzburg 0.217550 0.178928 0.071569 0.299646 1.000000 0.158482 0.048199 0.089337 -0.000661
Steiermark 0.059279 -0.066198 0.301180 0.276066 0.158482 1.000000 0.109836 0.094035 -0.124260
Tirol 0.078068 0.159309 0.137985 0.089327 0.048199 0.109836 1.000000 0.163011 0.144744
Vorarlberg -0.005213 0.022400 0.029835 0.059720 0.089337 0.094035 0.163011 1.000000 0.001220
Wien 0.153204 0.307858 0.304245 0.136485 -0.000661 -0.124260 0.144744 0.001220 1.000000